<?php
if ($this->Session->flash()) {
    echo $this->Session->flash();
}

$signup_info = $this->Session->read('signup_info');
$organisation = null;

if( isset($signup_info) && isset($signup_info['Organisation']) ) {
    $organisation = $signup_info['Organisation'];
}

?>

<form class='form-horizontal' method="post" action="<?php echo $this->Html->url(array('controller' => 'organisation', 'action' => 'register_info')); ?>" >

    <h3>Your Organization Details</h3>

    <div class='control-group'>
        <label class='control-label'>Name:</label>
        <div class='controls'>
            <input type="text" name="data[Organisation][name]" class="input-xlarge" required placeholder="Full Organisation Name" value="<?php echo isset($organisation) ? $organisation['Organisation']['name'] : ''; ?>" />
        </div>
    </div>
    
    <div class='control-group'>
        <label class='control-label'>Email:</label>
        <div class='controls'>
            <input type="email" name="data[Organisation][email]" class="input-large" required placeholder="Primary Contact Address" value="<?php echo isset($organisation) ? $organisation['Organisation']['email'] : ''; ?>" />
        </div>
    </div>

    <div class='control-group'>
        <label class='control-label'>Type:</label>
        <div class='controls'>
            <select name="data[Organisation][organisation_type_id]" required>
                <option value="">Choose Organisation Type</option>
                <?php
                $organisation_types = ClassRegistry::init('OrganisationType')->find('list');
                foreach ($organisation_types as $id => $name) {
                    $selected = isset($organisation) && $organisation['Organisation']['organisation_type_id'] == $id ? "selected" : "";
                    echo "<option value='$id' $selected>$name</option>";
                }
                ?>
            </select>
        </div>
    </div>

    <h3>Primary Login Account</h3>

    <div class='control-group'>
        <label class='control-label'>First Name:</label>
        <div class='controls'>
            <input type="text" name="data[OrganisationAccount][0][first_name]" class='input-medium' placeholder='First Name' required value="<?php echo isset($organisation) ? $organisation['OrganisationAccount'][0]['first_name'] : ''; ?>" />
        </div>
    </div>
    
    <div class='control-group'>
        <label class='control-label'>Last Name:</label>
        <div class='controls'>
            <input type='text' name='data[OrganisationAccount][0][last_name]' class='input-medium' placeholder='Last Name' required value="<?php echo isset($organisation) ? $organisation['OrganisationAccount'][0]['last_name'] : ''; ?>" />
        </div>
    </div>

    <div class='control-group'>
        <label class='control-label'>Email Address:</label>
        <div class='controls'>
            <input type="email" name="data[OrganisationAccount][0][username]" class="input-large" required placeholder="Username" value="<?php echo isset($organisation) ? $organisation['OrganisationAccount'][0]['username'] : ''; ?>" />
        </div>
    </div>

    <div class='control-group'>
        <label class='control-label'>Password:</label>
        <div class='controls'>
            <input type="password" name="data[OrganisationAccount][0][password]" class="input-medium" required placeholder="Password" />
            <input type="hidden" name="data[OrganisationAccount][0][pass_salt]" value="<?php echo rand(10000, 99999); ?>" />
            <input type="hidden" name="data[OrganisationAccount][0][type]" value="primary" />
            <input type="hidden" name="data[OrganisationAccount][0][active]" value="1" />
        </div>
    </div>

    <div class='form-actions'>
        <a class='btn' href='<?php echo $this->Html->url(array('action' => 'register_subscription')); ?>'><i class='icon icon-backward'></i> Back</a>
        <button type="submit" class="btn btn-success"><i class='icon icon-forward'></i> Continue</button>
        <a class="btn btn-cancel" href='<?php echo $this->Html->url(array('action' => 'register_cancel')); ?>' >Cancel</a>
    </div>
</form>